<?php
namespace App\Http\Controllers\Api\Ly;
use App\Common\Responses;
use App\Utils\Logic\Ly\WxLoginLogic;
use App\Http\Controllers\Controller;
use App\Utils\Service\Ly\WxLogin;
use Illuminate\Http\Request;

class WxLoginController extends Controller
{
    function login(Request $request)
    {
        try {
            if(!$request->post()) throw new \Exception('请求方式不正确');
            $code=$request->post('code');
            $userInfo=WxLogin::getOpenidByCode($code);
            $result=WxLoginLogic::wxLogin($userInfo);
            return Responses::success($result,200,'登录成功');
        }catch (\Exception $e)
        {
            return Responses::error([],200,$e->getMessage());
        }
    }
}
